/**
 * 
 */
package com.miolr.module.core.api;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import com.miolr.core.query.PageModel;
import com.miolr.module.core.model.Message;
import com.miolr.module.core.service.MessageService;

/**
 * @author iday
 * 
 */
@Named
@Path("/message")
public class MessageResource {
	@Inject
	private MessageService service;

	@GET
	@Produces({ MediaType.APPLICATION_JSON })
	public List<Message> getmessages(
			@DefaultValue("1") @QueryParam("page") int page,
			@DefaultValue("20") @QueryParam("max-record") int maxRecord) {
		return service.queryAll(new PageModel(page, maxRecord), true, null);
	}

	@GET
	@Path("{id:[\\d]+}")
	@Produces({ MediaType.APPLICATION_JSON })
	public Message getmessage(@PathParam("id") long id) {
		Message m = service.findByPrimaryKey(id);
		return m;
	}

	@POST
	@Produces({ MediaType.APPLICATION_JSON })
	@Consumes({ MediaType.APPLICATION_JSON })
	public Message save(Message message) {
		service.save(message);
		return message;
	}

	@PUT
	@Produces({ MediaType.APPLICATION_JSON })
	@Consumes({ MediaType.APPLICATION_JSON })
	public Message update(Message message) {
		service.update(message);
		return message;
	}

	@DELETE
	@Produces({ MediaType.APPLICATION_JSON })
	@Consumes({ MediaType.APPLICATION_JSON })
	public void delete(Message message) {
		service.delete(message);
	}

}
